using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDWKUNDE
    {
        public DataRow Convert2DWKUNDE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDWKUNDE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DWKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DWKKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["DWKKENNUNG1"] = " ".PadRight(6 ); 
         dwReturn["DWKVERSNR1"] = " ".PadRight(8 ); 
         dwReturn["DWKVERSPATCH1"] = " ".PadRight(2 ); 
         dwReturn["DWKVERSDAT1"] = " ".PadRight(0 ); 
         dwReturn["DWKDIR1"] = " ".PadRight(32 ); 
         dwReturn["DWKUSERPASS1"] = " ".PadRight(16 ); 
         dwReturn["DWKKENNUNG2"] = " ".PadRight(6 ); 
         dwReturn["DWKVERSNR2"] = " ".PadRight(8 ); 
         dwReturn["DWKVERSPATCH2"] = " ".PadRight(2 ); 
         dwReturn["DWKVERSDAT2"] = " ".PadRight(0 ); 
         dwReturn["DWKDIR2"] = " ".PadRight(32 ); 
         dwReturn["DWKUSERPASS2"] = " ".PadRight(16 ); 
         dwReturn["DWKKENNUNG3"] = " ".PadRight(6 ); 
         dwReturn["DWKVERSNR3"] = " ".PadRight(8 ); 
         dwReturn["DWKVERSPATCH3"] = " ".PadRight(2 ); 
         dwReturn["DWKVERSDAT3"] = " ".PadRight(0 ); 
         dwReturn["DWKDIR3"] = " ".PadRight(32 ); 
         dwReturn["DWKUSERPASS3"] = " ".PadRight(16 ); 
         dwReturn["DWKKENNUNG4"] = " ".PadRight(6 ); 
         dwReturn["DWKVERSNR4"] = " ".PadRight(8 ); 
         dwReturn["DWKVERSPATCH4"] = " ".PadRight(2 ); 
         dwReturn["DWKVERSDAT4"] = " ".PadRight(0 ); 
         dwReturn["DWKDIR4"] = " ".PadRight(32 ); 
         dwReturn["DWKUSERPASS4"] = " ".PadRight(16 ); 
         dwReturn["DWKPLANDAT"] = " ".PadRight(0 ); 
         dwReturn["DWKPLANTAET"] = " ".PadRight(50 ); 
         dwReturn["DWKWARTBIS"] = " ".PadRight(0 ); 
         dwReturn["DWKHOTLINE"] = " ".PadRight(1 ); 
         dwReturn["DWKANZBEN"] = " ".PadRight(0 ); 
         dwReturn["DWKBTRBSYS"] = " ".PadRight(2 ); 
         dwReturn["DWKDB"] = " ".PadRight(2 ); 
         dwReturn["DWKCOBOL"] = " ".PadRight(2 ); 
         dwReturn["DWKFERNKZ"] = " ".PadRight(2 ); 
         dwReturn["DWKFERNRUF"] = " ".PadRight(20 ); 
         dwReturn["DWKINST"] = " ".PadRight(1 ); 
         dwReturn["DWKMODKZ"] = " ".PadRight(1 ); 
         dwReturn["DWKSOURCE"] = " ".PadRight(1 ); 
         dwReturn["DWKKDPROG"] = " ".PadRight(1 ); 
         dwReturn["DWKKDIFG"] = " ".PadRight(1 ); 
         dwReturn["DWKCLIENT"] = " ".PadRight(6 ); 
         dwReturn["DWKFILLER"] = " ".PadRight(92 ); 
         dwReturn["DWKAENZL"] = " ".PadRight(0 ); 
         dwReturn["DWKAENB"] = " ".PadRight(8 ); 
         dwReturn["DWKAEND"] = " ".PadRight(0 ); 
         dwReturn["DWKNEUB"] = " ".PadRight(8 ); 
         dwReturn["DWKNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDWKUNDE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDWKUNDE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDWKUNDE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDWKUNDE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDWKUNDE(dwLocal, ITXDBVERSION);
            }
            UpdateDWKUNDE(dwLocal);
        }
        public void InsertDWKUNDE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DWKUNDE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDWKUNDE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DWKUNDE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DWKUNDE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DWKUNDE";
            Return = Result;
            return Return;
        }
        public void DeleteDWKUNDE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DWKUNDE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDWKUNDE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DWKUNDE SET "
                    +"DWKMANDANT= :DWKMANDANT,"
                    +"DWKKUNDNR= :DWKKUNDNR,"
                    +"DWKKENNUNG1= :DWKKENNUNG1,"
                    +"DWKVERSNR1= :DWKVERSNR1,"
                    +"DWKVERSPATCH1= :DWKVERSPATCH1,"
                    +"DWKVERSDAT1= :DWKVERSDAT1,"
                    +"DWKDIR1= :DWKDIR1,"
                    +"DWKUSERPASS1= :DWKUSERPASS1,"
                    +"DWKKENNUNG2= :DWKKENNUNG2,"
                    +"DWKVERSNR2= :DWKVERSNR2,"
                    +"DWKVERSPATCH2= :DWKVERSPATCH2,"
                    +"DWKVERSDAT2= :DWKVERSDAT2,"
                    +"DWKDIR2= :DWKDIR2,"
                    +"DWKUSERPASS2= :DWKUSERPASS2,"
                    +"DWKKENNUNG3= :DWKKENNUNG3,"
                    +"DWKVERSNR3= :DWKVERSNR3,"
                    +"DWKVERSPATCH3= :DWKVERSPATCH3,"
                    +"DWKVERSDAT3= :DWKVERSDAT3,"
                    +"DWKDIR3= :DWKDIR3,"
                    +"DWKUSERPASS3= :DWKUSERPASS3,"
                    +"DWKKENNUNG4= :DWKKENNUNG4,"
                    +"DWKVERSNR4= :DWKVERSNR4,"
                    +"DWKVERSPATCH4= :DWKVERSPATCH4,"
                    +"DWKVERSDAT4= :DWKVERSDAT4,"
                    +"DWKDIR4= :DWKDIR4,"
                    +"DWKUSERPASS4= :DWKUSERPASS4,"
                    +"DWKPLANDAT= :DWKPLANDAT,"
                    +"DWKPLANTAET= :DWKPLANTAET,"
                    +"DWKWARTBIS= :DWKWARTBIS,"
                    +"DWKHOTLINE= :DWKHOTLINE,"
                    +"DWKANZBEN= :DWKANZBEN,"
                    +"DWKBTRBSYS= :DWKBTRBSYS,"
                    +"DWKDB= :DWKDB,"
                    +"DWKCOBOL= :DWKCOBOL,"
                    +"DWKFERNKZ= :DWKFERNKZ,"
                    +"DWKFERNRUF= :DWKFERNRUF,"
                    +"DWKINST= :DWKINST,"
                    +"DWKMODKZ= :DWKMODKZ,"
                    +"DWKSOURCE= :DWKSOURCE,"
                    +"DWKKDPROG= :DWKKDPROG,"
                    +"DWKKDIFG= :DWKKDIFG,"
                    +"DWKCLIENT= :DWKCLIENT,"
                    +"DWKFILLER= :DWKFILLER,"
                    +"DWKAENZL= :DWKAENZL,"
                    +"DWKAENB= :DWKAENB,"
                    +"DWKAEND= :DWKAEND,"
                    +"DWKNEUB= :DWKNEUB,"
                    +"DWKNEUD= :DWKNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DWKMANDANT", OracleType.NVarChar).Value = dwData["DWKMANDANT"].ToString(); 
          or1.Parameters.Add("DWKKUNDNR", OracleType.NVarChar).Value = dwData["DWKKUNDNR"].ToString(); 
          or1.Parameters.Add("DWKKENNUNG1", OracleType.NVarChar).Value = dwData["DWKKENNUNG1"].ToString(); 
          or1.Parameters.Add("DWKVERSNR1", OracleType.NVarChar).Value = dwData["DWKVERSNR1"].ToString(); 
          or1.Parameters.Add("DWKVERSPATCH1", OracleType.NVarChar).Value = dwData["DWKVERSPATCH1"].ToString(); 
          or1.Parameters.Add("DWKVERSDAT1", OracleType.NVarChar).Value = dwData["DWKVERSDAT1"].ToString(); 
          or1.Parameters.Add("DWKDIR1", OracleType.NVarChar).Value = dwData["DWKDIR1"].ToString(); 
          or1.Parameters.Add("DWKUSERPASS1", OracleType.NVarChar).Value = dwData["DWKUSERPASS1"].ToString(); 
          or1.Parameters.Add("DWKKENNUNG2", OracleType.NVarChar).Value = dwData["DWKKENNUNG2"].ToString(); 
          or1.Parameters.Add("DWKVERSNR2", OracleType.NVarChar).Value = dwData["DWKVERSNR2"].ToString(); 
          or1.Parameters.Add("DWKVERSPATCH2", OracleType.NVarChar).Value = dwData["DWKVERSPATCH2"].ToString(); 
          or1.Parameters.Add("DWKVERSDAT2", OracleType.NVarChar).Value = dwData["DWKVERSDAT2"].ToString(); 
          or1.Parameters.Add("DWKDIR2", OracleType.NVarChar).Value = dwData["DWKDIR2"].ToString(); 
          or1.Parameters.Add("DWKUSERPASS2", OracleType.NVarChar).Value = dwData["DWKUSERPASS2"].ToString(); 
          or1.Parameters.Add("DWKKENNUNG3", OracleType.NVarChar).Value = dwData["DWKKENNUNG3"].ToString(); 
          or1.Parameters.Add("DWKVERSNR3", OracleType.NVarChar).Value = dwData["DWKVERSNR3"].ToString(); 
          or1.Parameters.Add("DWKVERSPATCH3", OracleType.NVarChar).Value = dwData["DWKVERSPATCH3"].ToString(); 
          or1.Parameters.Add("DWKVERSDAT3", OracleType.NVarChar).Value = dwData["DWKVERSDAT3"].ToString(); 
          or1.Parameters.Add("DWKDIR3", OracleType.NVarChar).Value = dwData["DWKDIR3"].ToString(); 
          or1.Parameters.Add("DWKUSERPASS3", OracleType.NVarChar).Value = dwData["DWKUSERPASS3"].ToString(); 
          or1.Parameters.Add("DWKKENNUNG4", OracleType.NVarChar).Value = dwData["DWKKENNUNG4"].ToString(); 
          or1.Parameters.Add("DWKVERSNR4", OracleType.NVarChar).Value = dwData["DWKVERSNR4"].ToString(); 
          or1.Parameters.Add("DWKVERSPATCH4", OracleType.NVarChar).Value = dwData["DWKVERSPATCH4"].ToString(); 
          or1.Parameters.Add("DWKVERSDAT4", OracleType.NVarChar).Value = dwData["DWKVERSDAT4"].ToString(); 
          or1.Parameters.Add("DWKDIR4", OracleType.NVarChar).Value = dwData["DWKDIR4"].ToString(); 
          or1.Parameters.Add("DWKUSERPASS4", OracleType.NVarChar).Value = dwData["DWKUSERPASS4"].ToString(); 
          or1.Parameters.Add("DWKPLANDAT", OracleType.NVarChar).Value = dwData["DWKPLANDAT"].ToString(); 
          or1.Parameters.Add("DWKPLANTAET", OracleType.NVarChar).Value = dwData["DWKPLANTAET"].ToString(); 
          or1.Parameters.Add("DWKWARTBIS", OracleType.NVarChar).Value = dwData["DWKWARTBIS"].ToString(); 
          or1.Parameters.Add("DWKHOTLINE", OracleType.NVarChar).Value = dwData["DWKHOTLINE"].ToString(); 
          or1.Parameters.Add("DWKANZBEN", OracleType.NVarChar).Value = dwData["DWKANZBEN"].ToString(); 
          or1.Parameters.Add("DWKBTRBSYS", OracleType.NVarChar).Value = dwData["DWKBTRBSYS"].ToString(); 
          or1.Parameters.Add("DWKDB", OracleType.NVarChar).Value = dwData["DWKDB"].ToString(); 
          or1.Parameters.Add("DWKCOBOL", OracleType.NVarChar).Value = dwData["DWKCOBOL"].ToString(); 
          or1.Parameters.Add("DWKFERNKZ", OracleType.NVarChar).Value = dwData["DWKFERNKZ"].ToString(); 
          or1.Parameters.Add("DWKFERNRUF", OracleType.NVarChar).Value = dwData["DWKFERNRUF"].ToString(); 
          or1.Parameters.Add("DWKINST", OracleType.NVarChar).Value = dwData["DWKINST"].ToString(); 
          or1.Parameters.Add("DWKMODKZ", OracleType.NVarChar).Value = dwData["DWKMODKZ"].ToString(); 
          or1.Parameters.Add("DWKSOURCE", OracleType.NVarChar).Value = dwData["DWKSOURCE"].ToString(); 
          or1.Parameters.Add("DWKKDPROG", OracleType.NVarChar).Value = dwData["DWKKDPROG"].ToString(); 
          or1.Parameters.Add("DWKKDIFG", OracleType.NVarChar).Value = dwData["DWKKDIFG"].ToString(); 
          or1.Parameters.Add("DWKCLIENT", OracleType.NVarChar).Value = dwData["DWKCLIENT"].ToString(); 
          or1.Parameters.Add("DWKFILLER", OracleType.NVarChar).Value = dwData["DWKFILLER"].ToString(); 
          or1.Parameters.Add("DWKAENZL", OracleType.NVarChar).Value = dwData["DWKAENZL"].ToString(); 
          or1.Parameters.Add("DWKAENB", OracleType.NVarChar).Value = dwData["DWKAENB"].ToString(); 
          or1.Parameters.Add("DWKAEND", OracleType.NVarChar).Value = dwData["DWKAEND"].ToString(); 
          or1.Parameters.Add("DWKNEUB", OracleType.NVarChar).Value = dwData["DWKNEUB"].ToString(); 
          or1.Parameters.Add("DWKNEUD", OracleType.NVarChar).Value = dwData["DWKNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
